home *** CD-ROM | disk | FTP | other *** search
/ Cracking 1 / Cracking I..iso / Tools / Ostatní / aPLib v0.26b / src / asm / depack16.asm < prev    next >
Encoding:
Assembly Source File  |  2001-12-15  |  2.9 KB  |  170 lines

  1. ;;
  2. ;; aPLib compression library  -  the smaller the better :)
  3. ;;
  4. ;; TASM / MASM / WASM 16bit assembler depacker
  5. ;;
  6. ;; Copyright (c) 1998-2000 by Joergen Ibsen / Jibz
  7. ;; All Rights Reserved
  8. ;;
  9. ;; -> 16bit by METALBRAIN (metalb@bart.us.es)
  10. ;;
  11.  
  12. .MODEL TINY                   ; or whatever your code is :)
  13.  
  14. .CODE
  15. .386
  16.  
  17. PUBLIC _aP_depack16_asm
  18.  
  19. _aP_depack16_asm:
  20.     push   es
  21.     push   ebp
  22.     mov    bp, sp
  23.     pushad
  24.  
  25.     mov    esi, [bp + 8]      ; C calling convention
  26.     mov    edi, [bp + 12]
  27.  
  28.     push   bp
  29.  
  30.     xor    eax, eax           ; convert segm:offs to linear
  31.     xchg   ax, si
  32.     shr    esi, 12
  33.     add    esi, eax
  34.  
  35.     xor    ax, ax             ; convert segm:offs to linear
  36.     xchg   ax, di
  37.     shr    edi, 12
  38.     add    edi, eax
  39.  
  40.     push   edi
  41.  
  42.     cld
  43.     mov    dl, 80h
  44. literal:
  45.     call   getesi
  46. putedi_nexttag:
  47.     call   putedi
  48.     jmp    short nexttag
  49.  
  50. normalcodepair:
  51.     xchg   ax, cx
  52.     dec    ax
  53.     shl    eax, 8
  54.     call   getesi
  55.     call   getgamma
  56.     cmp    eax, 32000
  57.     jae    short domatch_with_2inc
  58.     cmp    ah, 5
  59.     jae    short domatch_with_inc
  60.     cmp    ax, 127
  61.     ja     short domatch_new_lastpos
  62.  
  63. domatch_with_2inc:
  64.     inc    ecx
  65. domatch_with_inc:
  66.     inc    ecx
  67.  
  68. domatch_new_lastpos:
  69.     xchg   eax, ebp
  70. domatch_lastpos:
  71.     mov    eax, ebp
  72.  
  73. domatch:
  74.     push   esi
  75.     mov    esi, edi
  76.     sub    esi, eax
  77. repmovsb:
  78.     call   getesi
  79.     call   putedi
  80.     loopd  repmovsb
  81.     pop    esi
  82.  
  83. nexttag:
  84.     call   getbit
  85.     jnc    short literal
  86.     xor    ecx, ecx
  87.     call   getbit
  88.     jnc    short codepair
  89.     xor    eax, eax
  90.     call   getbit
  91.     jnc    short shortmatch
  92.     inc    cx
  93.     mov    al, 10h
  94. getmorebits:
  95.     call   getbit
  96.     adc    al, al
  97.     jnc    short getmorebits
  98.     jnz    short domatch
  99.     jmp    short putedi_nexttag
  100.  
  101. codepair:
  102.     call   getgamma_no_ecx
  103.     dec    cx
  104.     loop   normalcodepair
  105.     push   WORD PTR domatch_new_lastpos
  106.  
  107. getgamma:
  108.     xor    ecx, ecx
  109. getgamma_no_ecx:
  110.     inc    cx
  111. getgammaloop:
  112.     call   getbit
  113.     adc    ecx, ecx
  114.     call   getbit
  115.     jc     short getgammaloop
  116.     ret
  117.  
  118. shortmatch:
  119.     call   getesi
  120.     shr    ax, 1
  121.     jz     short donedepacking
  122.     adc    cx, cx
  123.     jmp    short domatch_with_2inc
  124.  
  125. getbit:
  126.     add    dl, dl
  127.     jnz    short stillbitsleft
  128.     pushf
  129.     xchg   ax, dx
  130.     call   getesi
  131.     xchg   ax, dx
  132.     popf
  133.     adc    dl, dl
  134. stillbitsleft:
  135.     ret
  136.  
  137. getesi:
  138.     push   esi
  139.     pop    bx
  140.     pop    bx
  141.     ror    bx, 4
  142.     mov    es, bx
  143.     mov    al, es:[si]
  144.     inc    esi
  145.     ret
  146.  
  147. putedi:
  148.     push   edi
  149.     pop    bx
  150.     pop    bx
  151.     ror    bx, 4
  152.     mov    es, bx
  153.     mov    es:[di], al
  154.     inc    edi
  155.     ret
  156.  
  157. donedepacking:
  158.     pop    eax
  159.  
  160.     pop    bp
  161.     sub    edi, eax
  162.     mov    [bp - 4], edi      ; return unpacked length in eax
  163.  
  164.     popad
  165.     pop    ebp
  166.     pop    es
  167.     ret
  168.  
  169. END
  170.